package com.dykj.controller;

import com.HttpUtils;
import com.alibaba.fastjson.JSONObject;
import com.dykj.dao.CustinfoMapper;
import com.dykj.dao.SalesorderinfoMapper;
import com.dykj.dao.SupplierbasicinfoMapper;
import com.dykj.dao.UserMapper;
import com.dykj.entity.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: LALA
 * Date: 2018-11-23
 * Time: 17:00
 */
@RestController
@RequestMapping("/test")
public class CustomController {

    @Autowired
    private CustinfoMapper custinfoMapper;

    @Autowired
    private SupplierbasicinfoMapper supplierbasicinfoMapper;

    @Autowired
    private SalesorderinfoMapper salesorderinfoMapper;



    @Autowired
    private UserMapper userMapper;

    @RequestMapping("/user")
    public void usertest(User user){
        Map<String,String> map = new HashMap<String,String>();
        map.put("name", "sarin");
        String result = HttpUtils.get("https://www.baidu.com/",map);
        System.out.println(result);
        //需要确认一下这边参数的格式是用问好的形式还是直接后缀的形式
    }

    @RequestMapping("/custom")
    public List<Custinfo> custommsg(){

        String json = HttpUtils.get("http://192.168.2.129:666/custom",null);
        List<Custinfo> list = JSONObject.parseArray(json,Custinfo.class);
        /*for(Custinfo custinfo : list){
            this.custinfoMapper.insertSelective(custinfo);
        }*/
        System.out.println("111");
        return list;

    }
    /*供应商基础资料，无参*/
    @RequestMapping("/supplier")
    public   List<Supplierbasicinfo> suppliermsg(){
        String json = HttpUtils.get("http://192.168.2.129:666/supplier",null);
        List<Supplierbasicinfo> list = JSONObject.parseArray(json,Supplierbasicinfo.class);
       /* for(Supplierbasicinfo supplierbasicinfo:list){
            this.supplierbasicinfoMapper.insertSelective(supplierbasicinfo);
        }*/
        System.out.println("scuessful");
        return list;
    }
  /*  *//*外购入库单，时间*//*
    @RequestMapping("/purin")
    public  List<Purchaseorderinfo> getPurIn(){
        String json = HttpUtils.get("http://192.168.2.129:666/purIn",null);
        List<Purchaseorderinfo> list = JSONObject.parseArray(json,Purchaseorderinfo.class);
        return list;
    }*/
    /*采购订单，时间*/
  /*  public  String getPurOrder(){
        String json = HttpUtils.get("http://192.168.2.129:666/purOrder",null);
        return "";
    }*/
  /*销售订单*/
    @RequestMapping("/order")
    public  List<Salesorderinfo> order(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2013-01-01/2013-12-31",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();

        //this.salesorderinfoMapper.insert(list); Packet for query is too large (5,324,900 > 4,194,304)数据量不能太大
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }

    @RequestMapping("/order1")
    public  List<Salesorderinfo> order1(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2014-01-01/2014-12-31",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }
    @RequestMapping("/order2")
    public  List<Salesorderinfo> order2(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2015-01-01/2015-12-31",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }
    @RequestMapping("/order3")
    public  List<Salesorderinfo> order3(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2016-01-01/2016-12-31",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }
    @RequestMapping("/order4")
    public  List<Salesorderinfo> order4(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2017-01-01/2017-12-31",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }
    @RequestMapping("/order5")
    public  List<Salesorderinfo> order5(){
        String json = HttpUtils.get("http://192.168.2.129:666/saleOrder/2018-01-01/2018-11-23",null);
        //是不是可能是这个/位置错了
        List<Salesorderinfo> list = JSONObject.parseArray(json,Salesorderinfo.class);
        Long start = System.currentTimeMillis();
        for(Salesorderinfo salesorderinfo:list){
            this.salesorderinfoMapper.insertSelective(salesorderinfo);
        }
        Long end = System.currentTimeMillis();
        System.out.println(end-start);

        return list;
    }
}
